<!DOCTYPE html>
<html lang="ch">

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<link rel="stylesheet" href="css/mui.min.css">
		<link rel="stylesheet" type="text/css" href="css/main.css" />
		<script src="js/config.js"></script>
		<script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>
		<script src="js/mui.min.js"></script>
		<title></title>
	</head>

	<body>
		<div class="nav_con">
			<img class="nav_icon float_l" src="img/nav_icon_bar@2x.png" onclick="backPro()">消息
			<div class="clear"></div>
		</div>
		<!--hidden="hidden"-->
		<div class="set_wind"  id="deleInfo" hidden="hidden">
			<div class="set_wind_con">
				<div class="set_wind_mid">
					<p class="set_wind_title">是否删除此消息</p>
					<div class="set_wind_but">
						<p hidden="hidden" id="pp1"></p>
						<p class="set_wind_but_l float_l" onclick="canceldele()">取消</p>
						<p class="set_wind_but_r float_r" onclick="subdele()">确定</p>
						<div class="clear"></div>
					</div>
				</div>
			</div>
		</div>
		<div class="cd_nr" id="pullrefresh">
			<input id="msgv" type="hidden" value="false" />
			<div id="infoDiv">
				
			</div>
	</body>
	<script >
		var pageNum = 1;
		var pageSize = 2;
		var isOver = false;
		var list_map = new Array();
		var token = localStorage.getItem("key")
		//var token = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJzdWIiOiI1NSIsImlhdCI6MTU3MDc1OTE3MSwiZXhwIjoxNTcxMzYzOTcxfQ.Sre32f2jFV9dcKMAgKafHUmTnP103ljU-oMKK62De5LH7eK4zk4edIUsx3ZGD5Ib1jllRHVa1tpTEoxVgjvK4g';		
		mui.init({
		    pullRefresh: {
		      container: '#pullrefresh',
		      up : {
		      height:100,
		      auto:true,
		      contentrefresh : "正在加载...",
		      contentnomore:'没有更多数据了',
		        callback: SelectPosition
		      }
		    }
        });
        var mflag = true
        function SelectPosition() {
        	if($("#msgv").val() == "true"){
        		mflag = true
        	}
        	if(mflag){
        		$("#msgv").val("false")
        		mflag = false
	        	getinfoList();
		        mui('#pullrefresh').pullRefresh().endPullupToRefresh(isOver);
        	}
	    };
		function getinfoList(){
			$.ajax({
	            type: "POST",
	            url: url_prefix + "home/informationList",
	            data: {
	            	request: JSON.stringify({
						"token":token,
						"pageNum":pageNum,
						"pageSize":pageSize
					})   
	            },
	            dataType: "json",
	            success: function(data){   
	            	if(data.code == '200'){
	            		var proList = data.result.list
	            		var str = null;
	            		for(var i = 0;i<proList.length;i++){
	            			if(proList[i].msgStatue =='true'){
	            				str = '<div class="notice" style="background-color:#f6e9e9;" name="di1" id="infoState'+proList[i].msgId+'" signId="'+proList[i].signId+'"><div class="notice_portrait_con float_l" style="float: left;;width:18%">';
	            			}else{
	            				str = '<div class="notice" style="background-color:white;" name="di1" id="infoState'+proList[i].msgId+'" signId="'+proList[i].signId+'"><div class="notice_portrait_con float_l" style="float: left;;width:18%">';
	            			}	
	            			
	            			str = str + '<p style="color: #ffffff; line-height: 58px" id="title'+proList[i].signId+'">'+proList[i].msgTitle+'</p></div>';
	            			str = str + '<div class="notice_r float_l" style="float: left;width:70%"><p class="notice_title float_l">'+proList[i].msgTitle+'消息</p>';
	            			str = str + '<p class="notice_date float_r" id="time'+proList[i].signId+'">'+proList[i].msgTime+'</p>';
	            			str = str + '<p hidden="hidden" id="msgId'+proList[i].msgId+'">'+proList[i].msgId+'</p><p hidden="hidden" id="signId'+proList[i].signId+'">'+proList[i].signId+'</p><div class="clear"></div>';
	            			str = str + '<p style="font-size:12px;padding-top:5px;color:#c7b7b7">'+proList[i].msgContext+'</p></div>';	
	            			
	            			str = str + '<div class="clear"></div></div><div class="notice_fen"></div>';
	            			$("#infoDiv").append(str);
	            		}
	            		var tPage = 0;
		        		var ys = data.total%pageSize
		        		if(ys>0){
		        			tPage = data.total/pageSize + 1
		        		}else{
		        			tPage = data.total/pageSize
		        		}
		        		if(pageNum<tPage){
		        			if(proList.length < pageSize){
				                isOver = true;
	                            mui('#pullrefresh').pullRefresh().endPullupToRefresh(isOver);
	                        }
			        		if(isOver == false){
				   				 pageNum++;
							}
		        		}else{
		        			isOver = true;
			                mui('#pullrefresh').pullRefresh().endPullupToRefresh(isOver);
		        		}
	            		todelete();
	            	}else if (data.code == '300'){
						mui.toast("帐号在其他设备上登录")
						window.location.href="fastLogin.html"
					}else{
		        		mui.toast("连接服务器失败,请稍后重试``````");
		       		}
	            	$("#msgv").val("true")
	            },
	            error: function(XMLHttpRequest, textStatus, errorThrown) {
					mui.toast("连接服务器失败,请稍后重试``````");
				}
	       });
		};
		function backPro(){
			window.location.href = 'home.html'
		};
		var timeOutEvent=0;
		
		function todelete(){
			var n = document.getElementsByName("di1");
			$(n).each(function(){
				var Id = (this.id).split("infoState");
				var Id2 = $(this).attr("signId")
				var Id3 = $(this).attr("listId")
				$(this).on({						
					touchstart: function(e){
						timeOutEvent = setTimeout("longPress("+Id2+")",500);
					 	e.preventDefault();
					},
					touchmove: function(){
			            	clearTimeout(timeOutEvent); 
					    	timeOutEvent = 0;  
					},
					touchend: function(){
				   		clearTimeout(timeOutEvent);
						if(timeOutEvent!=0){	
						    toInfoDetails(Id[1],Id2,Id3) ;
						} 
						return false; 
					}			
			    })
			})
		};
		function subdele(){
			var signId = $("#pp1").html(); 		
    		$.ajax({
	            type: "POST",
	            url: url_prefix + "home/deleteInformation",
	            data: {
	            	request: JSON.stringify({
						"token":token,
						"signId":signId
					})   
	            },
	            dataType: "json",
	            success: function(data){
	            	if(data.code == '200'){
	            		mui.toast('删除成功')
	            		$("#deleInfo").hide();
		            	$("#infoDiv").empty();
		            	pageNum = 1
		            	SelectPosition()
	            	}else if (data.code == '300'){
						mui.toast("帐号在其他设备上登录")
						window.location.href="fastLogin.html"
					}else{
		        		mui.toast("连接服务器失败,请稍后重试``````");
		       		}
	            	
	            },
	            error: function(XMLHttpRequest, textStatus, errorThrown) {
					mui.toast("连接服务器失败,请稍后重试``````");
				}
	        });			
		};
		function longPress(id){ 
			timeOutEvent = 0; 
			$("#deleInfo").show();
			$("#pp1").html(id);
		};
		function toInfoDetails(msgId,signId,listId){
			$.ajax({
	            type: "POST",
	            url: url_prefix + "home/informationRead",
	            data: {
	            	request: JSON.stringify({
						"token":token,
						"signId":signId,
						"msgId":msgId
					})   
	            },
	            dataType: "json",
	            success: function(data){   
	            	if(data.code == '200'){
						var values1 = $("#title"+signId).html()
						var values2 = $("#time"+signId).html()
						var values3 = msgId;
						var url = 'msgDetail.html?values1='+values1+'&values2='+values2+'&values3='+values3;		
						window.location.href = encodeURI(url);
	            	}else if (data.code == '300'){
						mui.toast("帐号在其他设备上登录")
						window.location.href="fastLogin.html"
					}else{
		        		mui.toast("连接服务器失败,请稍后重试``````");
		       		}
	            },
	            error: function(XMLHttpRequest, textStatus, errorThrown) {
					mui.toast("连接服务器失败,请稍后重试``````");
				}
	        });			
		};
		function canceldele(){
			$("#deleInfo").hide();
		}
	</script>
</html>